﻿namespace CatClient.Message.Spi.Heartbeat
{
    using CatClient.Util;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Xml.Serialization;

    [XmlRoot("thread")]
    public class ThreadInfo : IRefresh
    {
        private readonly Stopwatch _stopwatch = new Stopwatch();

        public void Refresh()
        {
            this._stopwatch.Restart();
            this.Count = Process.GetCurrentProcess().Threads.Count;
            this._stopwatch.Stop();
            LogInfoWriter.GetInstance("Cat", 0, LogInfoWriter.LogLayout.Default).Info($"Heartbeat {"ThreadInfo"} refresh finish. {this._stopwatch.ElapsedMilliseconds}ms");
        }

        [XmlAttribute("count")]
        public int Count { get; set; }

        [XmlAttribute("daemon-count")]
        public int DaemonCount { get; set; }

        [XmlAttribute("peek-count")]
        public int PeekCount { get; set; }

        [XmlAttribute("managed-count")]
        public int ManagedCount { get; set; }

        [XmlAttribute("total-started-count")]
        public int TotalStartCount { get; set; }

        [XmlAttribute("cat-thread-count")]
        public int CatThreadCount { get; set; }

        [XmlAttribute("pigeon-thread-count")]
        public int PigeonThreadCount { get; set; }

        [XmlAttribute("http-thread-count")]
        public int HttpThreadCount { get; set; }

        [XmlElement("dump")]
        public string Dump { get; set; }
    }
}

